import { IInterview } from '@/types/interview';
import { PageContainer } from '@ant-design/pro-components';
import { message } from 'antd';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import InterviewForm from '../components/interviewForm';

// 请求方法
import InterviewController from '@/services/interview';

const AddInterview: React.FC = () => {
  const navigate = useNavigate();

  const [newInterviewInfo] = useState<IInterview>({
    interviewTitle: '',
    interviewContent: '',
    typeId: '',
  } as IInterview);

  /**
   * 新增面试题
   */
  function handleSubmit(interviewInfo: IInterview) {
    InterviewController.addInterview(interviewInfo);
    // 跳转回首页
    navigate('/interview/interview-list');
    message.success('新增题目成功');
  }

  return (
    <PageContainer>
      <div className="container" style={{ width: 1000 }}>
        <InterviewForm
          type="add"
          handleSubmit={handleSubmit}
          interviewInfo={newInterviewInfo}
        />
      </div>
    </PageContainer>
  );
};

export default AddInterview;
